/*
 * Copyright 2016-2019 yoara
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package yhao.infra.service.datasource;


import org.apache.ibatis.session.SqlSession;
import yhao.infra.common.model.Pagination;

import java.util.List;

/**
 * DAO基类，提供常用增删改查接口
 *
 * @author yoara
 */
public interface BaseDao {
	/**
	 * 扩展MyBatis的分页查询
	 * @param statement 查询数据的sql
	 * @param statementCount 查询总数的sql，可能会造成严重的性能瓶颈，建议新写一条，若确认没有性能问题，也可复用statement
	 * @param parameter 传参
     */
	<T> Pagination<T> selectList(String statement, String statementCount, Object parameter, Pagination<T> page);
	/**
	 * 查询结果集总数
	 */
	int selectCount(String statement, Object parameter);
	/**
	 * 查询一个结果
	 */
	Object selectOne(String statement, Object parameter);
	/**
	 * 更新操作
	 */
	int update(String statement, Object parameter);
	/**
	 * 删除操作
	 */
	int delete(String statement, Object parameter);
	/**
	 * 新增操作
	 */
	int insert(String statement, Object parameter);
	/**
	 * 查询结果集
	 */
	List<?> selectList(String statement);
	/**
	 * 查询结果集
	 */
	List<?> selectList(String statement, Object parameter);
	/**
	 * 查询结果集
	 */
	<T> List<T> selectList(String statement, Object parameter, int pageSize, int pageIndex);
	/**
	 * 执行sql
	 */
	void executeSql(String sql);

	SqlSession getSqlSession();
}
